(function($) {
        dynamicKey();
        var _ajax = $.ajax;
        $.ajax = function(opt) {
            if (opt.data != '' && opt.data != undefined) {
                var isEncrypt = new Object();
                var noEncrypt = new Object();
                if (opt.contentType == "application/json") {
                    noEncrypt = opt.data
                } else {
                    for (var index in opt.data) {
                        var arrayName = index;
                        if (opt.data[arrayName] != undefined && opt.data[arrayName].length > 460) {
                            noEncrypt[arrayName] = opt.data[arrayName]
                        } else {
                            isEncrypt[arrayName] = opt.data[arrayName]
                        }
                    }
                }
                opt.data = noEncrypt;
                opt.data.keyScript = AesEncrypt(RsaEncrypt(JSON.stringify(isEncrypt)))
            }
            var _opt = $.extend(opt, {
                beforeSend: function(jqXHR, settings) {}
            });
            return _ajax(_opt)
        }
    }
)(jQuery);
function dynamicKey() {
    if (window.publicKey == undefined || window.publicKey == null || window.publicKey == '') {
        $.ajax({
            type: 'GET',
            async: false,
            url: Globals.ctx + "/dynamicKey/generate",
            data: {
                nowDate: new Date()
            },
            success: function(data) {
                if (data.success) {
                    window.publicKey = data.body
                }
            }
        })
    }
}
function RsaEncrypt(message) {
    var encrypt = new JSEncrypt();
    encrypt.setPublicKey(window.publicKey);
    var encrypted = encrypt.encryptLong(message);
    return encrypted.toString()
}
function AesEncrypt(message) {
    var key = CryptoJS.enc.Utf8.parse("40fee27ca7174eb6");
    var srcs = CryptoJS.enc.Utf8.parse(message);
    var encrypted = CryptoJS.AES.encrypt(srcs, key, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
    });
    return encrypted.toString()
}
